package com.nanxhs.proxy.cglib;

import net.sf.cglib.core.DebuggingClassWriter;
import net.sf.cglib.proxy.Proxy;

/**
 * @author: haibin.tang
 * @date: 2021/2/5
 */
public class Main {

    public static void main(String[] args) {
        //将cglib生成的代理类输出到指定的目录
        System.setProperty(DebuggingClassWriter.DEBUG_LOCATION_PROPERTY, "e://cglib_class");

        OrderService orderService = (OrderService) Proxy.newProxyInstance(CgLibDynamicProxy.class.getClassLoader(), new Class[]{OrderService.class}, new CgLibDynamicProxy(new OrderServiceImpl()));
        System.out.println(orderService.create("HUAWEI P20 旗舰版"));

        System.out.println("-------------------------------------------------------------------");

        CglibMethodInterceptor cglibMethodInterceptor = new CglibMethodInterceptor(new StockService());
        StockService stockProxy = (StockService) cglibMethodInterceptor.getProxy(StockService.class);
        System.out.println(stockProxy.getStock());
    }
}
